package com.say.framework.idworker;

import org.hibernate.MappingException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.IdentityGenerator;

import java.io.Serializable;

/**
 * 自定义ID生成器
 * @version 1.0
 */
public class IDGenerator extends IdentityGenerator{
    @Override
    public Serializable generate(SessionImplementor session, Object object) throws MappingException {
        Object id = IdWorker.generateId();
        if (id != null) {
            return (Serializable) id;
        }
        return super.generate(session, object);
    }


}
